<?php 
class Tuser extends AppModel {


	var $name = 'Tuser';
	var $useTable = 'tuser';
	var $primaryKey = "id";
	/**
     * check user psw
     * @param string $user username
     * @param string $psw password
     * @return
     */
	function checkUserPsw($user = NULL, $psw = NULL) {
		if ( empty($user) || empty($psw)) {
			return FALSE;
		}
		$conditions = "f_uname='".strtolower($user)."' and f_psw='".md5($psw)."' and f_status='1' ";

		if (1 == $this->findCount($conditions)) {

			return TRUE;
		}
		return FALSE;
	}

	/**
     * create new user
     * @param string $user username
     * @param string $psw password
     * @return
     */
	function createUser($user = NULL, $psw = NULL) {
		if ( empty($user) || empty($psw)) {
			return FALSE;
		}
		$conditions = "f_uname='".strtolower($user)."' ";

		if (1 == $this->findCount($conditions)) {
			return FALSE;
		}

		$data = array("f_uname"=>strtolower($user), "f_psw"=>md5($psw), "f_status"=>1);
		if ($this->save($data)) {
			return TRUE;
		}
		return FALSE;
	}
	/**
     * find user info by userName
     * @param string $user username
     * @return
     */
	function findByUserName($user = NULL) {
		if ( empty($user)) {
			return FALSE;
		}
		$conditions = "f_uname='".strtolower($user)."' ";
		return $this->find($conditions);
	}

}
?>
